﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using JHECIS.DataModel.DictModel;
using JHECIS.DataModel.Enum;
using JHECIS.Interface;
using Microsoft.Practices.ServiceLocation;
using MS.Common.Extension;
using MS.Common.Helpers;

namespace JHECIS.BLL.Triage.Common
{
    public class TriageLevelConvert : IValueConverter
    {
       /// <summary>
       /// 构造方法 袁凤超 2022-03-28
       /// </summary>
        public TriageLevelConvert() 
        {
            
        }
        /// <summary>
        /// 分诊等级转图片展示  袁凤超 2022-03-28
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return DependencyProperty.UnsetValue;
            var result = string.Empty;
            if (double.TryParse(value.ToString(), out double status))
            {
               
                triagelevel item = DictCacheManager.Instance.triageLevelList?.Find(o => o.ID == status.ToString());

                byte[] bitReturn = null;
                if (item != null && !string.IsNullOrEmpty(item.ID) && item.LEVELIMG != null)
                {
                    bitReturn = (byte[])item.LEVELIMG;
                    return ImageHelper.ByteArrayToBitmapImage(bitReturn);

                }
                else
                {
                    switch (status)
                    {
                        case (double)TriageLevelEnum.FirstLevel:
                            result = "/JHECIS.Patients;component/Resources/1.png";
                            break;
                        case (double)TriageLevelEnum.SecondLevel:
                            result = "/JHECIS.Patients;component/Resources/2.png";
                            break;
                        case (double)TriageLevelEnum.ThirdLevel:
                            result = "/JHECIS.Patients;component/Resources/3.png";
                            break;
                        case (double)TriageLevelEnum.FouthLevel:
                            result = "/JHECIS.Patients;component/Resources/4a.png";
                            break;
                        case (double)TriageLevelEnum.FifthLevel:
                            result = "/JHECIS.Patients;component/Resources/4b.png";
                            break;
                        case (double)TriageLevelEnum.InfectLevel:
                            result = "/JHECIS.Patients;component/Resources/6.png";
                            break;
                        default:
                            break;
                    }

                    return result;
                }


            }

            return result;


        }
        /// <summary>
        /// 接口实现  袁凤超 2022-03-28
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return string.Empty;
        }
    }
}